<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>会员登录</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css"
          type="text/css"/>
    <script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"
            type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"
            type="text/javascript"></script>
    <!-- 引入自定义css文件 style.css -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css"/>

    <style>
        body {
            margin-top: 20px;
            margin: 0 auto;
        }

        .carousel-inner .item img {
            width: 100%;
            height: 300px;
        }

        #traderefund {
            display: none;
        }
    </style>
</head>

<body>
<jsp:include page="head.jsp"/>
<div class="container">
    <div class="row">

        <div style="margin:0 auto; margin-top:10px;width:950px;">
            <strong>我的订单
                <button onclick="track()">物流查询</button>
            </strong>
            <table class="table table-bordered">
                <c:forEach items="${requestScope.page.list}" var="order">
                    <tbody class="${order.oid}">
                    <tr class="success">
                        <th colspan="5">订单编号:${order.oid}
                        </th>
                    </tr>
                    <tr class="warning">
                        <th>图片</th>
                        <th>商品</th>
                        <th>价格</th>
                        <th>数量</th>
                        <th>小计</th>
                    </tr>
                    <c:forEach items="${order.orderItems}" var="item">
                        <tr class="active">
                            <td width="60" width="40%">
                                <input type="hidden" name="id" value="22">
                                <img src="${pageContext.request.contextPath}/${item.product.image}" width="70"
                                     height="60">
                            </td>
                            <td width="30%">
                                <a target="_blank">${item.product.name}</a>
                            </td>
                            2
                            <td width="20%">
                                ￥${item.product.shopPrice}
                            </td>
                            <td width="10%">
                                    ${item.count}
                            </td>
                            <td width="15%">
                                <span class="subtotal">￥${item.subTotal}</span>
                            </td>
                        </tr>
                    </c:forEach>
                    <tr class="success" class="${order.oid}">
                        <th colspan="3"></th>
                        <th>订单总价</th>
                        <th>￥${order.total}
                            <c:if test="${order.state == 0}">
                                <a href="${pageContext.request.contextPath}/order/orderPay.do?oid=${order.oid}">付款</a>
                            </c:if>
                            <c:if test="${order.state == 1}">
                                <a href="#">已付款</a>
                                <a href="javascript:void(0)" onclick="reFound()">退款</a>
                                <form id="traderefund" name=traderefund action="" method=post
                                      target="_blank">
                                    <div id="body3" class="tab-content" name="divcontent">
                                        <dl class="content">
                                                <%--<dt>商户订单号 ：</dt>--%>
                                            <dd>
                                                <input type="hidden" id="WIDTRout_trade_no" name="WIDTRout_trade_no"
                                                       value="${order.oid}"/>
                                            </dd>
                                            <hr class="one_line">
                                                <%--<dt>支付宝交易号 ：</dt>--%>
                                            <dd>
                                                <input type="hidden" id="WIDTRtrade_no" name="WIDTRtrade_no"/>
                                            </dd>
                                            <hr class="one_line">
                                                <%--<dt>退款金额 ：</dt>--%>
                                            <dd>
                                                <input type="hidden" id="WIDTRrefund_amount" name="WIDTRrefund_amount"
                                                       value="${order.total}"/>
                                            </dd>
                                            <hr class="one_line">
                                                <%--<dt>退款原因 ：</dt>--%>
                                            <dd>
                                                <input type="hidden" id="WIDTRrefund_reason" name="WIDTRrefund_reason"/>
                                            </dd>
                                            <hr class="one_line">
                                                <%--<dt>退款请求号 ：</dt>--%>
                                            <dd>
                                                <input type="hidden" id="WIDTRout_request_no"
                                                       name="WIDTRout_request_no"/>
                                            </dd>
                                            <hr class="one_line">
                                            <dt></dt>
                                            <dd id="btn-dd">
                                            </dd>
                                        </dl>
                                    </div>
                                </form>
                            </c:if>
                            <c:if test="${order.state == -1}">
                                <a href="#">已退款</a>
                            </c:if>
                            <a href="javascript:void(0)" onclick="deleteByOid('${order.oid}')">删除</a>
                        </th>
                    </tr>
                    </tbody>

                    <tr class="${order.oid}">
                        <th colspan="5" height="5px"></th>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</div>
<h3 align="center">
    <ul class="pagination">
        <c:if test="${requestScope.page.pageIndex!=0}">
            <li>
                <a href="/order/orderList.do?pageId=${requestScope.page.pageIndex-1}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
        </c:if>
        <c:if test="${requestScope.page.pageIndex==0}">
            <li>
                <a href="#" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
        </c:if>

        <c:forEach begin="${requestScope.page.start}" end="${requestScope.page.end}" var="i" step="1">
            <c:if test="${requestScope.page.pageIndex==i}">
                <li class="active"><a href="/order/orderList.do?pageId=${i}">${i+1}</a></li>
            </c:if>
            <c:if test="${requestScope.page.pageIndex!=i}">
                <li><a href="/order/orderList.do?pageId=${i}">${i+1}</a></li>
            </c:if>
        </c:forEach>

        <c:if test="${requestScope.page.pageIndex!=requestScope.page.pageTotal}">
            <li>
                <a href="/order/orderList.do?pageId=${requestScope.page.pageIndex+1}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </c:if>
        <c:if test="${requestScope.page.pageIndex==requestScope.page.pageTotal}">
            <li>
                <a href="#" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </c:if>
    </ul>
</h3>
<%--<h3 align="center" id="deletePage">--%>
<%--<ul class="pagination">--%>
<%--<c:if test="${requestScope.page.pageNum!=1}">--%>
<%--<li>--%>
<%--<a href="${pageContext.request.contextPath}/order/orderList.do?pageId=${requestScope.page.pageNum-1}"--%>
<%--aria-label="Previous">--%>
<%--<span aria-hidden="true">&laquo;</span>--%>
<%--</a>--%>
<%--</li>--%>
<%--</c:if>--%>
<%--<c:if test="${requestScope.page.pageNum==1}">--%>
<%--<li>--%>
<%--<a href="#" aria-label="Previous">--%>
<%--<span aria-hidden="true">&laquo;</span>--%>
<%--</a>--%>
<%--</li>--%>
<%--</c:if>--%>
<%--<!----%>
<%--navigateFirstPage    start--%>
<%--navigateLastPage     end--%>
<%---->--%>
<%--<c:forEach begin="${requestScope.page.navigateFirstPage}"--%>
<%--end="${requestScope.page.navigateLastPage}" var="i" step="1">--%>
<%--<c:if test="${requestScope.page.pageNum==i}">--%>
<%--<li class="active"><a--%>
<%--href="${pageContext.request.contextPath}/order/orderList.do?pageId=${i}">${i}</a>--%>
<%--</li>--%>
<%--</c:if>--%>
<%--<c:if test="${requestScope.page.pageNum!=i}">--%>
<%--<li><a href="${pageContext.request.contextPath}/order/orderList.do?pageId=${i}">${i}</a>--%>
<%--</li>--%>
<%--</c:if>--%>
<%--</c:forEach>--%>

<%--<c:if test="${requestScope.page.pageNum!=requestScope.page.pages}">--%>
<%--<li>--%>
<%--<a href="${pageContext.request.contextPath}/order/orderList.do?pageId=${requestScope.page.nextPage}"--%>
<%--aria-label="Next">--%>
<%--<span aria-hidden="true">&raquo;</span>--%>
<%--</a>--%>
<%--</li>--%>
<%--</c:if>--%>
<%--<c:if test="${requestScope.page.pageNum==requestScope.page.pages}">--%>
<%--<li>--%>
<%--<a href="#" aria-label="Next">--%>
<%--<span aria-hidden="true">&raquo;</span>--%>
<%--</a>--%>
<%--</li>--%>
<%--</c:if>--%>
<%--</ul>--%>
<%--</h3>--%>
<jsp:include page="foot.jsp"/>
</body>
<script>
    function deleteByOid(oid) {
        $.ajax(
            {
                url: "${pageContext.request.contextPath}/order/deleteByOid.do",
                data: {
                    oid: oid
                },
                success: function (oid) {
                    $("." + oid).remove();
                }
            }
        )
    }

    function reFound() {
        // $("#traderefund").attr("action","/payJsp/alipay.trade.refund.jsp")
        // $("#traderefund").submit()
        if (confirm("确认退款吗？")) {
            $.ajax(
                {
                    url: "/payJsp/alipay.trade.refund.jsp",
                    data: {
                        WIDTRout_trade_no: $("#WIDTRout_trade_no").val(),
                        WIDTRtrade_no: $("#WIDTRtrade_no").val(),
                        WIDTRrefund_amount: $("#WIDTRrefund_amount").val(),
                        WIDTRrefund_reason: $("#WIDTRrefund_reason").val(),
                        WIDTRout_request_no: $("#WIDTRout_request_no").val()
                    },
                    success: function (msg) {
                        var mm = $.parseJSON(msg);
                        console.log(mm)
                        var message = mm.alipay_trade_refund_response.msg;
                        if (message == "Success") {
                            $.ajax(
                                {
                                    url: "/order/reFoundUpdateOrderState.do",
                                    data: {
                                        oid: $("#WIDTRout_trade_no").val()
                                    },
                                    success: function (msg) {
                                        if (msg == 1) {
                                            alert("退款成功")
                                            window.location.reload();
                                        }
                                    }
                                }
                            )
                        } else {
                            alert("退款失败")
                            window.location.reload();
                        }
                    }
                }
            )
        }
    }

    function track() {
        location.href = "/jsp/track.jsp"
    }
</script>
</html>